<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General  License
*/

  require('includes/application_top.php');

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO);

// Begin product_previous_next
  include(DIR_WS_MODULES . 'products_next_previous.php');
// End product_previous_next

  $product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
  $product_check = tep_db_fetch_array($product_check_query);

  require(DIR_WS_INCLUDES . 'template_top.php');

  if ($product_check['total'] < 1) {
?>

<div class="contentContainer">
  <div class="contentText">
    <?php echo TEXT_PRODUCT_NOT_FOUND; ?>
  </div>

  <div style="float: right;">
    <?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'triangle-1-e', tep_href_link(FILENAME_DEFAULT)); ?>
  </div>
</div>

<?php
  } else {//edit by donghp
    $product_info_query = tep_db_query("select p.products_id,p.products_review_count,p.products_rating,
	p.products_quantity,p.products_weight, pd.products_name, pd.products_description, pd.products_specifications, pd.products_experience, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
    $product_info = tep_db_fetch_array($product_info_query);

    tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . (int)$languages_id . "'");

    if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
      $products_price = '<del>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</del> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
    } else {
      $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
    }

    if (tep_not_null($product_info['products_model'])) {
      $products_name = $product_info['products_name'] . '<br /><span class="smallText">[' . $product_info['products_model'] . ']</span>';
    } else {
      $products_name = $product_info['products_name'];
    }
?>

<?php
  if ($messageStack->size('product') > 0) {
    echo $messageStack->output('product');
  } 
   //----------add by donghp----------------------
  $manu_id = $product_info['manufacturers_id'];
  
  $m_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = " . $manu_id);
  
  $manufacture = tep_db_fetch_array($m_query);
 
  $p_review = $product_info['products_review_count'];
  $p_rating = $product_info['products_rating'];
  $p_weight = $product_info['products_weight'];
  $p_quan   = $product_info['products_quantity'];
  
  $charges = 3;
  
  $p_price2 = $currencies->display_price($product_info['products_price']+$charges, tep_get_tax_rate($product_info['products_tax_class_id']));
  
  $p_charges= $currencies->display_price($charges, tep_get_tax_rate($product_info['products_tax_class_id']));
  
  if ($p_quan >0) { $in_stock='<span class="stockGreen">'.TEXT_IN_STOCK.'</span>'; }
  else { $in_stock='<span class="stockRed">'.TEXT_OUT_OF_STOCK.'</span>'; }
?>
<?php /*
echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); ?>

<div class="producInfor">
  <h1><?php echo $products_name; ?></h1>
  <p>by <a href="#" class="manufacturer"><?php echo $manufacture['manufacturers_name'];?></a></p>
  <h1 style="float: right;"><?php echo
   $products_price; ?></h1>    
</div>
*/?>
<div class="prod_detail">
	  <div class="thumbsec">
                	<!--div id="slider2" class="prod_gallery">
                        <div class="contentdiv" style="z-index: 1; visibility: visible; opacity: 1; display: none; "><a rel="example_group" href="images/prod_big.jpg" title="Lorem ipsum dolor sit amet"><img src="images/prod1.gif" alt=""></a></div>
                        <div class="contentdiv" style="display: none; "><a rel="example_group" href="images/prod_big.jpg" title="Lorem ipsum dolor sit amet"><img src="images/prod2.gif" alt=""></a></div>
                        <div class="contentdiv" style="display: none; "><a rel="example_group" href="images/prod_big.jpg" title="Lorem ipsum dolor sit amet"><img src="images/prod3.gif" alt=""></a></div>
                        <div class="contentdiv" style="z-index: 2; visibility: visible; display: block; opacity: 1; "><a rel="example_group" href="images/prod_big.jpg" title="Lorem ipsum dolor sit amet"><img src="images/prod4.gif" alt=""></a></div>
                    </div>
                    <div class="galleryscrol">
                        <a href="#" class="prevbtn">&nbsp;</a>
                        <div class="anyClass" id="paginate-slider2" style="visibility: visible; overflow-x: hidden; overflow-y: hidden; position: relative; z-index: 2; left: 0px; width: 159px; ">
                            <ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; position: relative; list-style-type: none; z-index: 1; width: 530px; left: -371px; "><li style="overflow-x: hidden; overflow-y: hidden; float: left; width: 48px; height: 46px; "><a href="#" class="toc" rel="2"><img src="images/prod2_thumb.gif" alt=""></a></li><li style="overflow-x: hidden; overflow-y: hidden; float: left; width: 48px; height: 46px; "><a href="#" class="toc" rel="3"><img src="images/prod3_thumb.gif" alt=""></a></li><li style="overflow-x: hidden; overflow-y: hidden; float: left; width: 48px; height: 46px; "><a href="#" class="toc" rel="4"><img src="images/prod4_thumb.gif" alt=""></a></li>
                                <li style="overflow-x: hidden; overflow-y: hidden; float: left; width: 48px; height: 46px; "><a href="#" class="toc" rel="1"><img src="images/prod1_thumb.gif" alt=""></a></li>
                                <li style="overflow-x: hidden; overflow-y: hidden; float: left; width: 48px; height: 46px; "><a href="#" class="toc" rel="2"><img src="images/prod2_thumb.gif" alt=""></a></li>
                                <li style="overflow-x: hidden; overflow-y: hidden; float: left; width: 48px; height: 46px; "><a href="#" class="toc" rel="3"><img src="images/prod3_thumb.gif" alt=""></a></li>
                                <li style="overflow-x: hidden; overflow-y: hidden; float: left; width: 48px; height: 46px; "><a href="#" class="toc selected" rel="4"><img src="images/prod4_thumb.gif" alt=""></a></li>
                            <li style="overflow-x: hidden; overflow-y: hidden; float: left; width: 48px; height: 46px; "><a href="#" class="toc selected" rel="1"><img src="images/prod1_thumb.gif" alt=""></a></li><li style="overflow-x: hidden; overflow-y: hidden; float: left; width: 48px; height: 46px; "><a href="#" class="toc" rel="2"><img src="images/prod2_thumb.gif" alt=""></a></li><li style="overflow-x: hidden; overflow-y: hidden; float: left; width: 48px; height: 46px; "><a href="#" class="toc" rel="3"><img src="images/prod3_thumb.gif" alt=""></a></li></ul>
                        </div>
                        <a href="#" class="nextbtn">&nbsp;</a>
                    </div>
                    <script type="text/javascript" src="js/gallery.js"></script>
                	<script type="text/javascript" src="js/jcarousellite_1.0.1.js"></script-->
    <!--------- Begin div product image ------>   
        <?php
    if (tep_not_null($product_info['products_image'])) {
      $pi_query = tep_db_query("select image, htmlcontent from " . TABLE_PRODUCTS_IMAGES . " where products_id = '" . (int)$product_info['products_id'] . "' order by sort_order");

      if (tep_db_num_rows($pi_query) > 0) {
?>

    <div id="piGal" style="float: left;">
      <ul>
<?php
        $pi_counter = 0;
        while ($pi = tep_db_fetch_array($pi_query)) {
          $pi_counter++;

          $pi_entry = '        <li><a href="';

          if (tep_not_null($pi['htmlcontent'])) {
            $pi_entry .= '#piGalimg_' . $pi_counter;
          } else {
            $pi_entry .= tep_href_link(DIR_WS_IMAGES . $pi['image']);
          }

          $pi_entry .= '" target="_blank" rel="fancybox">' . tep_image(DIR_WS_IMAGES . $pi['image']) . '</a>';

          if (tep_not_null($pi['htmlcontent'])) {
            $pi_entry .= '<div style="display: none;"><div id="piGalimg_' . $pi_counter . '">' . $pi['htmlcontent'] . '</div></div>';
          }

          $pi_entry .= '</li>';

          echo $pi_entry;
        }
?>
      </ul>
    </div> 

	<script type="text/javascript" src="jquery/jRating.jquery.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$('.star_rating').jRating({
			 	type:'small',
				isDisabled : true,
				length : 5,
				decimalLength : 1,
				rateMax : 5,
			});
		});
	</script>
<script type="text/javascript">
$('#piGal ul').bxGallery({
  maxwidth: 300,
  maxheight: 200,
  thumbwidth: <?php echo (($pi_counter > 1) ? '50' : '0'); ?>,
  thumbcontainer: 300,
  thumbcrop:false,
  thumbplacement: 'bottom', 
  load_image: 'ext/jquery/bxGallery/spinner.gif'
});
</script>

<?php
      } else {
?>

    <div id="piGal" style="float: left;">
      <?php echo '<a href="' . tep_href_link(DIR_WS_IMAGES . $product_info['products_image']) . '" target="_blank" rel="fancybox">' . tep_image(DIR_WS_IMAGES . $product_info['products_image'], addslashes($product_info['products_name']), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . '</a>'; ?>
    </div>
<?php //products_id

      }
?>

<script type="text/javascript">
$("#piGal a[rel^='fancybox']").fancybox({
  cyclic: true
});
</script>

<?php
    }
?>
<!--------- End div gallary image ------>
           <div class="exemple">	
                <div class="star_rating" id="<?php echo $p_rating;?>_1"></div>
                <span class="reviews"><?php echo $p_rating.' out of 5 stars';?></span>	
        	</div>    
        	<div class="products_review">(Base on <?php echo $p_review;?> Experiences)
        	</div>
      </div>
                
      <div class="descshort">
               	<div class="title_prod"><?php echo $products_name; ?></div>                              
                <div class="manufac">by <a href="#"><?php echo $manufacture['manufacturers_name'];?></a></div>
                    
                    <hr  noshade="noshade" size="1"/>          
                    <div class="prices">
                    	<?php echo SPOT_PRICE;?> : <span class="newprice"><?php echo $products_price; ?></span>
   <?php echo NORMAL_PRICE;?> : <span class="oldprice"> <?php echo $p_price2; ?></span>  
   					</div>
                    
                    <hr  noshade="noshade" size="1"/>
                     
                    <div class="instock">
                      <div class="status"><?php echo $in_stock;?></div>
                      
                      <div class="addcart"><?php echo TEXT_QUANTITY;?>
                      <input type="text" name="cart_quantity[]" value="" size="4">
                      <input type="hidden" name="products_id[]" value="">            
                       </div>  
                     </div> 
                     
                    <hr noshade="noshade" size="1"/>
                    
                    <div class="freight">
                     <p>Freight Information:</p>
                         
                         <div class="line">
                             <span class="label_info">Country</span><?php echo tep_get_country_list('entry_country_id', tep_get_countries());?> 
                         </div>
                         
                         <div class="line">
                             <span class="label_info">Freight</span><select style="width:180px; vertical-align:top" name="cboFreight" id="cboFreight"><option value="3" selected="">Fedex Courier Service</option><option value="8">DHL Courier Service</option><option value="19">Local Pickup</option></select>
                             <?php echo tep_draw_button(IMAGE_BUTTON_OK ,'', tep_href_link("#",'')); ?>  
                         </div>
                         
                          <div class="line">
                             <span class="label_info">Charges</span>
                             <span class="newprice"><?php echo $p_charges;?> </span>                            
                         </div>
                    </div> 
                    <div class="clear"></div>
                </div>
</div>
<?php

// Begin product_previous_next
 // if ( ($product_check['total'] > 0) && ( (PREVIOUS_NEXT_PRODUCT_LINK_NAVIGATION == 'Top') || (PREVIOUS_NEXT_PRODUCT_LINK_NAVIGATION == 'Both') ) ) {
 //   echo $prevnextProductLinkDisplay;
 // }
// End product_previous_next

?>

<div class="contentContainer">
  <div class="contentText">

<?php //echo stripslashes($product_info['products_description']); ?>

<?php
    $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
    $products_attributes = tep_db_fetch_array($products_attributes_query);
    if (FALSE) {/*if ($products_attributes['total'] > 0) {  disable available options based on client request*/
?>

    <p><?php echo TEXT_PRODUCT_OPTIONS; ?></p>

    <p>
<?php
      $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name");
      while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
        $products_options_array = array();
        $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");
        while ($products_options = tep_db_fetch_array($products_options_query)) {
          $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);
          if ($products_options['options_values_price'] != '0') {
            $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
          }
        }

        if (is_string($HTTP_GET_VARS['products_id']) && isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
          $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
        } else {
          $selected_attribute = false;
        }
?>
      <strong><?php echo $products_options_name['products_options_name'] . ':'; ?></strong><br /><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?><br />
<?php
      }
?>
    </p>

<?php
    }
?>

    <div style="clear: both;"></div>

<?php
    if ($product_info['products_date_available'] > date('Y-m-d H:i:s')) {
?>

    <p style="text-align: center;"><?php echo sprintf(TEXT_DATE_AVAILABLE, tep_date_long($product_info['products_date_available'])); ?></p>

<?php
    }
?>

  </div>

<?php
// Begin product_previous_next
  if ( ($product_check['total'] > 0) && ( (PREVIOUS_NEXT_PRODUCT_LINK_NAVIGATION == 'Bottom') || (PREVIOUS_NEXT_PRODUCT_LINK_NAVIGATION == 'Both') ) ) {
    echo $prevnextProductLinkDisplay;
  }
// End product_previous_next
?>

<?php
    $reviews_query = tep_db_query("select count(*) as count from " . TABLE_REVIEWS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and reviews_status = 1");
    $reviews = tep_db_fetch_array($reviews_query);
?>

  <div class="buttonSet">
	<?php if ($products_price > 0) { ?>
    <span class="buttonAction"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_draw_button(IMAGE_BUTTON_IN_CART, 'cart', null, 'primary'); ?></span>
	<?php } else { ?>
	  <span class="buttonAction"><?php echo tep_draw_button(TEXT_CONTACT_US, 'cart', tep_href_link(FILENAME_CONTACT_US), 'primary'); ?></span>
	<? } ?>
    <?php echo tep_draw_button(IMAGE_BUTTON_REVIEWS . (($reviews['count'] > 0) ? ' (' . $reviews['count'] . ')' : ''), 'comment', tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params())); ?>
  </div>

<?php
    if ((USE_CACHE == 'true') && empty($SID)) {
      echo tep_cache_also_purchased(3600);
    } else {
      include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
    }
?>

</div>

</form>

<div id="tabs">
	<ul>
		<li><a href="#tabs-1"><?php echo TEXT_SPECIFICATIONS; ?></a></li>
		<li><a href="#tabs-2"><?php echo TEXT_DESCRIPTION; ?></a></li>
		<li><a href="#tabs-3"><?php echo TEXT_VIDEO; ?></a></li>
		<li><a href="#tabs-4"><?php echo TEXT_EXPERIENCES; ?></a></li>
		<li><a href="#tabs-5"><?php echo TEXT_QUESTIONS; ?></a></li>
	</ul>
	<div id="tabs-1">
<?php echo stripslashes($product_info['products_specifications']); ?>
	</div>
	<div id="tabs-2">
<?php echo stripslashes($product_info['products_description']); ?>
	</div>
	<div id="tabs-3">
		<p>Soon.</p>
	</div>
	<div id="tabs-4">
<?php echo stripslashes($product_info['products_experience']); ?>
	</div>
	<div id="tabs-5">
<!--start Product Questions--> 
<?php
$qtns_qry = tep_db_query("select * from  " . TABLE_PRODUCT_QUESTIONS . " where product_id='" . $HTTP_GET_VARS['products_id'] . "' and status='1' order by date_added limit " . MAX_DISPLAY_PRODUCT_QUESTIONS); 

$tab2content = '';
if (tep_db_num_rows($qtns_qry) == 0) 
{
$tab2content .= '<p>'.NO_PRODUCT_QUESTIONS.'</p>';
}
else
{
	$i = 0;
	$tab2content .= '<ol>';
	while($qtnslist = tep_db_fetch_array($qtns_qry))
	{
	$tab2content .= '<li><strong>' .$qtnslist['question'] . '</strong> By ' . $qtnslist['customer_name'] . ' <br> &nbsp;';
	$tab2content .= '<em>' . $qtnslist['answer'] .'</em></li>';
	$i++;
	}
	$tab2content .= '</ol>';

	if($i>=MAX_DISPLAY_PRODUCT_QUESTIONS)
	{
		$tab2content .= tep_draw_button(TEXT_VIEW_ALL, 'triangle-1-e', tep_href_link(FILENAME_PRODUCT_QUESTIONS, 'products_id='.$HTTP_GET_VARS['products_id']));
	}
}
		$tab2content .= tep_draw_button(TEXT_ASK_QUESTION, 'comment', tep_href_link(FILENAME_ASK_QUESTION, 'products_id='.$HTTP_GET_VARS['products_id']));

    echo  $tab2content;
?>
<!--end Product Questions-->
	</div>
</div>

<script>
$(function() {
	$( "#tabs" ).tabs();
});
</script>

<?php

  }

  require(DIR_WS_INCLUDES . 'template_bottom.php');
  require(DIR_WS_INCLUDES . 'application_bottom.php');
?>